package cn.xxc.system.controller;

import cn.xxc.basic.util.AjaxResult;
import cn.xxc.basic.util.PageList;
import cn.xxc.system.domain.Systemdictionarytype;
import cn.xxc.system.query.SystemdictionarytypeQuery;
import cn.xxc.system.service.SystemdictionarytypeSerivce;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("/systemdictionarytype")
public class SystemdictionarytypeController {
    @Autowired
    private SystemdictionarytypeSerivce systemdictionarytypeSerivce;



    @GetMapping
    public List<Systemdictionarytype> findAll(){
        return systemdictionarytypeSerivce.loadAll();
    }

    @GetMapping("/{id}")
    public Systemdictionarytype findOne(@PathVariable("id") Long id ){
        return systemdictionarytypeSerivce.loadByid(id);
    }

    @PutMapping
    public AjaxResult save(@RequestBody Systemdictionarytype systemdictionarytype){
        try {
            if (systemdictionarytype.getId()==null){
                systemdictionarytypeSerivce.save(systemdictionarytype);
            }else {
                systemdictionarytypeSerivce.update(systemdictionarytype);
            }
            return new AjaxResult();
        }catch (Exception e){
            return new AjaxResult(false, "系统繁忙，请重试！！");
        }
    }

    @DeleteMapping("/{id}")
    public AjaxResult del(@PathVariable("id")Long id){
        try {
            systemdictionarytypeSerivce.del(id);
            return new AjaxResult();
        }catch (Exception e){
            System.out.println(e.getMessage());
            return new AjaxResult(false, "系统繁忙，请重试！！");
        }
    }

    @PostMapping
    public PageList<Systemdictionarytype> queryList(@RequestBody SystemdictionarytypeQuery systemdictionarytypeQuery){
        try {
            Integer totals=systemdictionarytypeSerivce.queryCount(systemdictionarytypeQuery);
            List<Systemdictionarytype> data=systemdictionarytypeSerivce.queryData(systemdictionarytypeQuery);
            System.out.println(data);
            return new PageList<>(totals,data);
        }catch (Exception e){
            return new PageList<>();
        }
    }

    @PatchMapping
    public AjaxResult patchDel(@RequestBody Long[] ids){
        try {
            systemdictionarytypeSerivce.patchDel(ids);
            return new AjaxResult();
        }catch (Exception e){
            return new AjaxResult(false, "系统繁忙，请重试！！");
        }
    }
}
